package com.crunch.math;

/**
 * A class for 3D rays.
 */
public final class Ray3f {
	private Vector3f origin;
	private Vector3f direction;

	/**
	 * Constructs a ray with the given origin and direction.
	 */
	public Ray3f(Vector3f origin, Vector3f direction) {
		this.origin = new Vector3f(origin);
		this.direction = new Vector3f(direction);
	}

	/**
	 * Sets the ray to the values provided.
	 */
	public void set(Vector3f origin, Vector3f direction) {
		this.origin.set(origin);
		this.direction.set(direction);
	}

	/**
	 * Constructs a ray by copying the one provided.
	 */
	public Ray3f(Ray3f r) {
		this.origin = new Vector3f(r.origin);
		this.direction = new Vector3f(r.direction);
	}

	/**
	 * Sets the ray to the one provided.
	 */
	public void set(Ray3f r) {
		this.origin.set(r.origin);
		this.direction.set(r.direction);
	}

	/**
	 * Returns the ray's origin.
	 */
	public Vector3f getOrigin() {
		return new Vector3f(origin);
	}

	/**
	 * Sets the ray's origin.
	 */
	public void setOrigin(Vector3f origin) {
		this.origin.set(origin);
	}

	/**
	 * Returns the ray's direction.
	 */
	public Vector3f getDirection() {
		return new Vector3f(direction);
	}

	/**
	 * Sets the ray's direction.
	 */
	public void setDirection(Vector3f direction) {
		this.direction.set(direction);
	}

	/**
	 * Returns whether this ray is equal to the object {@code o}.
	 */
	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		} else if (o == null || !(o instanceof Ray3f)) {
			return false;
		} else {
			return equals((Ray3f) o);
		}
	}

	/**
	 * Returns a hash code for this object.
	 */
	@Override
	public int hashCode() {
		return origin.hashCode() ^ direction.hashCode();
	}

	/**
	 * Returns whether this ray is equal to the ray {@code r}.
	 */
	public boolean equals(Ray3f r) {
		return origin.equals(r.origin) && direction.equals(r.direction);
	}
}
